#!/usr/bin/python
#-*- coding: latin-1 -*-

from sys import argv
from urllib import urlencode
from socket import setdefaulttimeout
from urllib2 import Request, urlopen, URLError, HTTPError


# timeout in seconds
timeout = 10
setdefaulttimeout(timeout)

try: url = argv[1]
except IndexError: url = 'http://www.google.com'

user_agent = 'Mozilla/4.0 (compatible; MSIE 5.5; Windows NT)'
values = {'' : '' }
headers = { 'User-Agent' : user_agent }

data = urlencode(values)
req = Request(url, data, headers)
try:
	    response = urlopen(req)
except HTTPError, e:
	    print 'The server couldn\'t fulfill the request.'
	    print 'Error code: ', e.code
except URLError, e:
	    print 'We failed to reach a server.'
	    print 'Reason: ', e.reason
except ValueError, e:
	    print 'Invalid URL format.'
	    print 'url: %s.' % url
else:
	the_page = response.read()
	print the_page
